let fs = require('fs');
// npm install opentype.js@1.3.3  一个读取字体子集的库,svg格式可以看下test.js是怎么获取的
var opentype = require('opentype.js');
var similar = require('./similar1')
let svgPaths = {
  "0":`<path d="M3.73 76.45L2.53 77.22Q3.02 66.11 4.85 61.75L4.85 61.75Q6.68 56.13 10.41 53.10L10.41 53.10Q14.20 49.80 19.83 50.08L19.83 
  50.08Q27.98 50.08 32.27 56.62L32.27 56.62Q34.24 59.85 35.40 64.21Q36.56 68.57 36.91 76.45L36.91 76.45Q36.56 80.95 36.91 
  84.60L36.91 84.60Q35.72 88.33 34.59 91.14L34.59 91.14Q32.77 97.68 29.11 99.72L29.11 99.72Q25.45 102.74 19.83 102.74L19.83 
  102.74Q12.38 102.74 7.03 97.40L7.03 97.40Q3.02 91.07 3.73 76.45L3.73 76.45ZM9.49 75.95L9.49 76.45Q9.49 89.17 
  12.41 93.36Q15.33 97.54 19.72 97.54Q24.12 97.54 27.07 93.39L27.07 93.39Q29.88 89.10 30.09 76.02L30.09 76.02Q30.09 63.79
  27 59.50L27 59.50Q24.19 55.35 19.76 55.35L19.76 55.35Q15.33 55.21 12.38 59.01L12.38 59.01Q9.91 63.79 9.49 75.95L9.49 75.95Z"/>`,
  "1":`<path d="M26.86 102.53L26.86 101.20L19.62 102.18L20.53 60.70Q17.44 63.72 14.48 65.83L14.48 65.83Q10.97 68.01 7.03 69.27L 
  7.03 69.27L8.86 62.88Q13.08 61.05 17.65 57.53L17.65 57.53Q19.05 55.42 21.09 53.45L21.09 53.45Q21.94 51.77 22.99 50.22L22.99 
  50.22L27.63 50.78L26.86 102.53Z"/>`,
  "2":`<path d="M36.21 95.78L36.21 95.36L36.21 101.83L2.18 101.83Q2.18 99.58 2.95 97.47L2.95 97.47Q2.81 95.64 5.20 93.95L5.20 93.95Q5.63 
  92.97 7.10 90.58L7.10 90.58Q8.65 88.89 10.55 86.99L10.55 86.99L15.33 82.77Q19.55 79.33 22.36 76.66Q25.17 73.98
  26.72 71.88L26.72 71.88Q29.67 67.87 29.67 64.21Q29.67 60.55 26.09 57.95L26.09 57.95Q25.03 55.35 19.97 55.35L19.97 55.35
  Q15.40 56.05 11.74 59.01L11.74 59.01Q9.91 60.70 9.84 65.69L9.84 65.69L3.66 65.55Q4.01 57.60 7.38 53.88L7.38 53.88Q12.66
  50.08 20.11 49.09L20.11 49.09Q27.49 50.08 31.82 54.19Q36.14 58.30 36.14 64.42L36.14 64.42Q36.14 67.66 34.95 70.43Q33.75
  73.21 30.66 75.81L30.66 75.81Q29.25 78.41 26.82 80.70Q24.40 82.98 20.95 85.87L20.95 85.87Q19.13 88.26 16.24 89.88L16.24
  89.88Q13.71 91.49 13.64 92.34L13.64 92.34Q12.80 93.18 12.16 94.02L12.16 94.02Q11.53 95.08 10.97 95.78L10.97 95.78L36.21
  95.78Z"/>`,
  "3":`<path d="M9.35 87.77L9.35 87.34Q10.41 92.76 13.01 95.15L13.01 95.15Q15.54 97.33 19.41 97.54L19.41 97.54Q22.92 97.54 27 94.52L27 
  94.52Q30.02 91.35 30.02 86.89Q30.02 82.42 27.21 79.61L27.21 79.61Q24.26 76.73 19.97 76.73L19.97 76.73Q18.07 76.73 15.47 77.43L15.47 
  77.43L16.17 71.45Q16.59 71.88 16.80 71.95L16.80 71.95Q17.86 71.95 17.23 71.95L17.23 71.95Q21.30 71.10 24.47 69.91L24.47 
  69.91Q27.70 67.73 27.70 63.16L27.70 63.16Q27.77 59.29 25.38 57.53L25.38 57.53Q23.20 55.35 19.27 55.35L19.27 55.35Q15.61 55.35 
  13.71 57.53L13.71 57.53Q10.76 59.78 9.98 64.56L9.98 64.56L3.66 63.44Q4.85 56.97 8.93 53.59L8.93 53.59Q13.08 50.85 19.13 49.66L19.13 
  49.66Q22.92 50.08 26.93 51.98L26.93 51.98Q30.45 53.66 32.34 56.83Q34.24 59.99 34.24 63.47Q34.24 66.95 32.48 69.63L32.48 69.63Q31.29 
  72.30 26.09 73.91L26.09 73.91Q31.71 74.97 34.24 78.27L34.24 78.27Q36.49 82.63 36.77 86.64L36.77 86.64Q36.77 93.32 31.85 
  98.07Q26.93 102.81 19.41 102.81L19.41 102.81Q12.59 102.81 8.16 98.73L8.16 98.73Q3.66 94.23 3.02 89.10L3.02 89.10L9.35 87.77Z"/>`,
  "4":`<path d="M23.27 101.83L23.20 101.41L24.05 89.73L0.91 89.03L1.83 84.11L25.03 50.29L30.59 49.23L29.18 83.69L36.35 83.69L35.65 
  89.52L29.18 90.37L29.32 101.83L23.27 101.83ZM22.43 83.69L23.27 82.63L22.29 60.41L7.10 83.90L22.43 83.69Z"/>`,
  "5":`<path d="M2.67 88.33L9.63 87.84Q10.20 92.76 12.90 95.15Q15.61 97.54 19.62 97.54L19.62 97.54Q24.12 98.31 27.28 92.97L27.28 
  92.97Q30.59 90.44 30.41 84.95Q30.23 79.47 27.35 76.16L27.35 76.16Q24.61 73.28 18.56 73.28L18.56 73.28Q16.31 73.28 13.92 74.62L13.92 
  74.62Q11.74 76.02 9.63 78.20L9.63 78.20L4.08 77.50L9.07 50.99L34.73 50.99L34.73 57.04L14.20 57.74L10.62 70.89Q13.64 69.27 16.10 68.46Q18.56 
  67.66 21.09 66.95L21.09 66.95Q27.21 67.66 32.55 72.30L32.55 72.30Q37.13 76.94 37.13 83.41L37.13 83.41Q37.13 91.28 33.05 96.41L33.05 96.41Q28.05 
  103.30 19.55 102.74L19.55 102.74Q12.45 102.39 8.09 98.80L8.09 98.80Q3.59 94.80 2.67 88.33L2.67 88.33Z"/>`,
  "6":`<path d="M36.70 62.88L29.53 63.37Q28.69 59.64 27.14 58.02L27.14 58.02Q24.54 55.35 20.81 55.63L20.81 55.63Q17.79 55.35 14.70 56.97L14.70 
  56.97Q12.45 58.94 10.83 63.51L10.83 63.51Q9.91 65.41 9.46 68.39Q9 71.38 9 75.25L9 75.25Q11.32 71.73 14.59 70.08Q17.86 68.43 21.52 68.43L21.52 
  68.43Q27.77 68.43 32.24 73.11Q36.70 77.78 36.70 85.16L36.70 85.16Q36.21 89.95 34.66 93.95L34.66 93.95Q32.55 98.31 28.93 100.53Q25.31 102.74 
  20.60 102.74L20.60 102.74Q12.66 102.74 7.73 96.98L7.73 96.98Q2.74 90.86 2.74 77.71L2.74 77.71Q2.74 62.73 8.23 56.27L8.23 56.27Q12.16 50.08 
  21.16 50.08L21.16 50.08Q27.28 50.08 31.15 53.52L31.15 53.52Q35.02 56.83 36.70 62.88L36.70 62.88ZM9.98 85.38L9.98 85.02Q9.98 88.33 11.39 
  91.98L11.39 91.98Q12.80 93.53 16.24 95.99L16.24 95.99Q17.79 97.05 20.53 97.54L20.53 97.54Q23.48 97.54 27.35 94.30L27.35 94.30Q30.23 92.05 
  30.23 85.52L30.23 85.52Q30.23 80.24 28.34 77.08L28.34 77.08Q24.89 73.98 20.25 73.98L20.25 73.98Q16.03 73.98 13.01 77.08Q9.98 80.17 9.98 85.38L9.98 85.38Z"/>`,
  "7":`<path d="M2.74 57.04L3.38 57.04L3.38 50.92L36.77 50.78L36.49 55.91Q34.38 58.52 31.92 62.00Q29.46 65.48 26.37 69.84L26.37 69.84L22.71 
  78.77Q21.45 83.05 19.13 87.55L19.13 87.55Q18.70 94.16 17.16 102.32L17.16 102.32L10.62 101.83Q9.84 98.59 11.25 95.50L11.25 95.50Q10.97 91.49 
  13.01 87.06L13.01 87.06Q15.26 78.48 19.76 70.75L19.76 70.75Q21.66 66.39 23.70 62.59L23.70 62.59Q26.30 59.78 28.69 57.04L28.69 57.04L2.74 57.04Z"/>`,
  "8":`<path d="M12.80 73L12.73 73.91Q4.99 71.03 4.99 63.37L4.99 63.37Q4.99 57.60 8.09 53.88L8.09 53.88Q13.01 50.08 19.79 50.08Q26.58 50.08 30.66 54.02L30.66 
  54.02Q33.96 58.09 34.80 63.51L34.80 63.51Q34.80 71.03 27 73.14L27 73.14Q31.92 75.46 33.61 78.91L33.61 78.91Q36.84 82.35 36.84 87.06L36.84 
  87.06Q36.84 93.81 32.20 97.54L32.20 97.54Q27.49 102.74 19.86 102.74Q12.23 102.74 7.59 98.24L7.59 98.24Q2.95 93.95 2.95 86.92L2.95 86.92Q2.95 
  81.93 5.48 78.52Q8.02 75.11 12.80 73L12.80 73ZM10.62 63.16L11.46 63.16Q11.46 66.95 13.82 69.20Q16.17 71.45 19.97 71.45L19.97 71.45Q24.26 
  71.45 26.79 69.13L26.79 69.13Q29.04 66.95 28.27 64.42L28.27 64.42Q28.27 60.13 25.88 58.45L25.88 58.45Q23.48 55.35 20.46 55.63L20.46 55.63Q16.10 55.35 
  13.85 57.60L13.85 57.60Q10.97 59.92 10.62 63.16L10.62 63.16ZM9.42 86.92L9.42 86.92Q9.42 89.73 10.65 92.23Q11.88 94.73 14.55
  96.13L14.55 96.13Q17.02 97.54 19.97 97.54L19.97 97.54Q22.22 97.54 24.12 96.77L24.12 96.77Q26.79 95.99 27.42 94.59L27.42
  94.59Q30.23 91.77 30.30 87.17Q30.38 82.56 27.14 79.61L27.14 79.61Q24.33 76.66 19.79 76.66Q15.26 76.66 12.34 79.57Q9.42
  82.49 9.42 86.92Z"/>`,
  "9":`<path d="M9.91 89.38L9.98 89.38Q10.83 93.74 12.94 94.80L12.94 94.80Q15.12 97.54 18.56 97.54L18.56 97.54Q21.59 97.54 23.73 96.20Q25.88 
  94.87 27.28 92.62L27.28 92.62Q27.98 90.37 29.67 86.57L29.67 86.57Q30.09 84.74 30.38 82.07L30.38 82.07L30.59 78.91Q31.64 79.68 30.59 78.34L30.59 
  78.34Q30.59 77.99 30.52 77.57L30.52 77.57Q27.77 80.59 25.31 82.49L25.31 82.49Q22.15 84.32 18.21 84.74L18.21 84.74Q11.81 84.32 7.38 79.75L7.38 
  79.75Q3.02 74.62 2.95 67.52L2.95 67.52Q3.02 58.80 7.59 54.93L7.59 54.93Q12.16 50.08 19.20 50.08L19.20 50.08Q24.12 49.87 28.55 52.82L28.55 
  52.82Q32.98 55.49 34.73 60.48L34.73 60.48Q36.84 65.62 36.84 75.88L36.84 75.88Q36.84 84.95 34.73 90.75Q32.63 96.55 28.37 99.65Q24.12 102.74 
  18.42 102.74L18.42 102.74Q12.30 102.74 8.58 99.37L8.58 99.37Q4.71 95.99 3.94 89.88L3.94 89.88L9.91 89.38ZM29.88 67.23L29.88 67.23Q29.88 61.75 
  26.93 58.55Q23.98 55.35 19.97 55.35L19.97 55.35Q15.68 55.63 12.59 59.29L12.59 59.29Q9.49 62.10 9.49 67.73L9.49 67.73Q9.49
  72.79 12.45 76.23L12.45 76.23Q15.47 78.84 19.83 78.84Q24.19 78.84 26.58 75.74L26.58 75.74Q29.88 72.51 29.88 67.23Z"/>`
}
// str是那个字体字符的乱码,然后把乱码解析成svg
async function parseNum(str){
  return new Promise(function(resolve,reject){
    opentype.load('a.woff',function(err,font){
      if(err){
        reject('Font could not be loaded:' + err)
      }else {
        // 0,100 是xy值 72是字体文件的大小
        var path = font.getPath(str,0,100,72);
        let a = path.toSVG();
        let max = 0;
        let key = 0;
        let arr = [];
        for(let i = 0;i < 10; i++){
          let temp = similar(a,svgPaths[i]);
          if(max < temp){
            max = temp;
            key = i;
          }
          arr.push({temp,i})
        }
        resolve({key,max})
        // console.log(arr,key,similar(a,b),path);
      }
    })
  })
}

module.exports = parseNum;